//
//  RootCell.m
//  Together
//
//  Created by Wang Shuguang on 12-12-7.
//  Copyright (c) 2012年 Dawn. All rights reserved.
//

#import "RootCell.h"
#import <QuartzCore/QuartzCore.h>
#import "SDWebImageManager.h"

@implementation RootCell
@synthesize src = _src;
@synthesize downloadBtn;

- (void) dealloc{
    self.src = nil;
    [super dealloc];
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        iconView = [[UIImageView alloc] initWithFrame:CGRectMake(6, 8, 57, 57)];
        iconView.layer.cornerRadius = 10.0f;
        iconView.clipsToBounds = YES;
        [self addSubview:iconView];
        [iconView release];
        
        separateView = [[UIImageView alloc] initWithFrame:CGRectMake(6, 0, SCREEN_WIDTH - 12, 2)];
        separateView.image = [UIImage imageNamed:@"category_separate_light.png"];
        [self addSubview:separateView];
        [separateView release];
        
        UIImageView *seleBgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 71)];
        seleBgView.clipsToBounds = YES;
        seleBgView.contentMode = UIViewContentModeTop;
        seleBgView.image = [UIImage imageNamed:@"category_cellhighlighted_bg.png"];
        self.selectedBackgroundView = seleBgView;
        [seleBgView release];
        
        titleLbl = [[UILabel alloc] initWithFrame:CGRectMake(70, 12, SCREEN_WIDTH - 70, 22)];
        titleLbl.font = [UIFont systemFontOfSize:18.0f];
        titleLbl.textColor = [UIColor colorWithRed:33.0f/255.0f green:33.0f/255.0f blue:33.0f/255.0f alpha:1.0f];
        titleLbl.backgroundColor = [UIColor clearColor];
        [self addSubview:titleLbl];
        [titleLbl release];
        
        updateTimeLbl = [[UILabel alloc] initWithFrame:CGRectMake(70, 40, SCREEN_WIDTH - 70, 20)];
        updateTimeLbl.font = [UIFont systemFontOfSize:14.0f];
        updateTimeLbl.textColor = [UIColor colorWithRed:200.0f/255.0f green:200.0f/255.0f blue:200.0f/255.0f alpha:1.0f];
        updateTimeLbl.backgroundColor = [UIColor clearColor];
        [self addSubview:updateTimeLbl];
        [updateTimeLbl release];
        
        progressView = [[DDProgressView alloc] initWithFrame:CGRectMake(68, 48, SCREEN_WIDTH - 80, 4)];
        [progressView setOuterColor: [UIColor clearColor]] ;
        [progressView setInnerColor: [UIColor colorWithRed:40.0/255.0 green:202.0/255.0 blue:255.0/255.0 alpha:.8f]];
        [progressView setEmptyColor: [UIColor colorWithRed:204.0/255.0 green:214.0/255.0 blue:227.0/255.0 alpha:1.0f]];
        [self addSubview:progressView];
        [progressView release];
        
        downloadBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        downloadBtn.frame = CGRectMake(SCREEN_WIDTH - 40, 20, 26, 26);
        [downloadBtn setImage:[UIImage imageNamed:@"category_icon_download.png"] forState:UIControlStateNormal];
        [self addSubview:downloadBtn];

    }
    return self;
}


- (void) setIconWithName:(NSString *)name{
    iconView.image = [UIImage imageNamed:name];
}

- (void) setSeparateViewHidden:(BOOL)hidden{
    separateView.hidden = hidden;
    separateHidden = hidden;
}

- (void) setTitle:(NSString *)title{
    titleLbl.text = title;
}

- (void) setProgress:(float)progress{
    if (progress >= 1.0 || progress <= 0) {
        progressView.hidden = YES;
        updateTimeLbl.hidden = NO;
    }else{
        updateTimeLbl.hidden = YES;
        progressView.hidden = NO;
        [progressView setProgress:progress];
    }
}

- (void) setUpdateTime:(NSString *)time{
    updateTimeLbl.text = time;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
    
    if (selected) {
        separateView.hidden = YES;
    }else{
        separateView.hidden = (NO || separateHidden);
    }
    
}

- (void) setHighlighted:(BOOL)highlighted animated:(BOOL)animated{
    [super setHighlighted:highlighted animated:animated];
    if (highlighted) {
        separateView.hidden = YES;
    }else{
        separateView.hidden = (NO || separateHidden);
    }
}

@end
